package com.modificial.shiro.config;

import com.modificial.shiro.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * @author modificial
 * @date 2018/8/13
 * @company codingApi
 * @description
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ResponseStatus(code = HttpStatus.FORBIDDEN,reason = "用户无此权限")
    @ResponseBody
    @ExceptionHandler(value = AuthorizationException.class)
    public JsonResult jsonResult(){
        log.error("用户无此权限");
        return new JsonResult(HttpStatus.FORBIDDEN.value(),"用户无此权限",0);
    }
}
